home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr48 / stk100.zip / FINDSB.C < prev    next >
C/C++ Source or Header  |  1995-02-02  |  4KB  |  160 lines

  1. /******************************************************************************
  2. File:          findsb.c
  3. Tab stops: every 2 collumns
  4. Project:     FINDSB utility
  5. Copyright: 1994 DiamondWare, Ltd.  All rights reserved.
  6. Written:     Keith Weiner & Erik Lorenzen
  7. Purpose:     Example code to autodetect and print out the sound hardware
  8. History:     KW 10/21/94 Started
  9.                      KW/EL 02/01/95 Finalized
  10. ******************************************************************************/
  11.  
  12.  
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16.  
  17. #include "dws.h"
  18.  
  19.  
  20.  
  21. static void DisplayError(word errornum)
  22. {
  23.     switch (errornum)
  24.     {
  25.         /*
  26.          . Note that only those errors which could occur when calling
  27.          . dws_DetectHardWare are checked for.
  28.         */
  29.         case dws_ALREADYINITTED:
  30.         {
  31.             /*
  32.              . If we get here, it means you've called dws_Init() already.  Calling
  33.              . dws_DetectHardWare() at this point would cause zillions of
  34.              . problems if we let the call through.
  35.             */
  36.             printf("The STK was already initialized\n");
  37.  
  38.             break;
  39.         }
  40.         case dws_DetectHardware_UNSTABLESYSTEM:
  41.         {
  42.             /*
  43.              . Please report it to DiamondWare if you get here!
  44.              .
  45.              . Ideally, you would disable control-C here, so that the user can't
  46.              . hit control-alt-delete, causing SmartDrive to flush its (possibly
  47.              . currupt) buffers.
  48.             */
  49.             printf("The system is unstable!\n");
  50.             printf("Please power down now!");
  51.  
  52.             #define ever ;;
  53.             for (ever);
  54.         }
  55.  
  56.         /*
  57.          . The following three errors are USER/PROGRAMMER errors.  You forgot
  58.          . to fill the cardtyp struct full of -1's (except in those fields
  59.          . you intended to override, or the user (upon the unlikly event that
  60.          . the STK was unable to find a card) gave you a bad overide value.
  61.         */
  62.         case dws_DetectHardware_BADBASEPORT:
  63.         {
  64.             /*
  65.              . You set dov.baseport to a bad value, or
  66.              . didn't fill it with a -1.
  67.             */
  68.             printf("Bad port address\n");
  69.  
  70.             break;
  71.         }
  72.         case dws_DetectHardware_BADDMA:
  73.         {
  74.             /*
  75.              . You set dov.digdma to a bad value, or
  76.              . didn't fill it with a -1.
  77.             */
  78.             printf("Bad DMA channel\n");
  79.  
  80.             break;
  81.         }
  82.         case dws_DetectHardware_BADIRQ:
  83.         {
  84.             /*
  85.              . You set dov.digirq to a bad value, or
  86.              . didn't fill it with a -1.
  87.             */
  88.             printf("Bad IRQ level\n");
  89.  
  90.             break;
  91.         }
  92.         default:
  93.         {
  94.             /*
  95.              . This should never occur and probably won't affect sound
  96.              . play(?).  If it happens please contact DiamondWare.
  97.             */
  98.  
  99.             printf("I'm confused!  Where am I?  HOW DID I GET HERE????\n");
  100.             printf("The ERROR number is: %d\n",errornum);
  101.         }
  102.     }
  103. }
  104.  
  105.  
  106. void main(void)
  107. {
  108.     dws_DETECTOVERRIDES dov;
  109.     dws_DETECTRESULTS     dres;
  110.  
  111.     printf("\nFINDSB is Copyright 1994 DiamondWare, Ltd.\nAll rights reserved.\n\n\n");
  112.  
  113.     /*
  114.      . We need to set every field to -1 in dws_DETECTOVERRIDES struct; this
  115.      . tells the STK to autodetect everything.    Any other value
  116.      . overrides the autodetect routine, and will be accepted on
  117.      . faith, though the STK will verify it if possible.
  118.     */
  119.     dov.baseport = (word)-1;
  120.     dov.digdma     = (word)-1;
  121.     dov.digirq     = (word)-1;
  122.  
  123.     if (!dws_DetectHardWare(&dov, &dres))
  124.     {
  125.         DisplayError(dws_ErrNo());
  126.         exit(-1);
  127.     }
  128.  
  129.     if (dres.capability & (dws_capability_FM | dws_capability_DIG))
  130.     {
  131.         printf("Base port is %x hex.\n\n", dres.baseport);
  132.  
  133.         if (dres.mixtyp > 1)
  134.         {
  135.             printf("The sound hardware supports mixing.\n\n");
  136.         }
  137.         else
  138.         {
  139.             printf("The sound hardware does not support mixing.\n\n");
  140.         }
  141.  
  142.         if (dres.capability & dws_capability_FM)
  143.         {
  144.             printf("The sound hardware supports FM music playback.\n\n");
  145.         }
  146.  
  147.         if (dres.capability & dws_capability_DIG)
  148.         {
  149.             printf("The sound hardware supports digitized sound playback.\n");
  150.  
  151.             printf("The sound hardware uses DMA channel %d and IRQ level %d.\n\n",
  152.                          dres.digdma, dres.digirq);
  153.         }
  154.     }
  155.     else
  156.     {
  157.         printf(" No sound hardware detected.\n");
  158.     }
  159. }
  160.